#include "scriptfunctions.h"
#include "searchdialog.h"

#include <QScriptEngine>
#include <QScriptValue>
#include <QMessageBox>
#include <QApplication>
#include <QtGui/QAbstractItemView>
#include <QtGui/QDesktopWidget>
#include <QDebug>

QScriptValue  msgBox(QScriptContext *context, QScriptEngine *engine)
{
    QString text = context->argument(0).toString();
    QString title =  context->argument(1).isUndefined()?"":context->argument(1).toString();
    QMessageBox::Icon icon = context->argument(1).isUndefined()?QMessageBox::NoIcon:static_cast<QMessageBox::Icon>(context->argument(2).toInt32());
    QMessageBox msg;    
    msg.setText(text);
    msg.setWindowTitle(title);
    msg.setIcon(icon);
#ifdef Q_OS_ANDROID
    msg.setWindowFlags(Qt::ToolTip);
    msg.setStyleSheet("QDialog{ background-color: rgb(235, 242, 255);border: 1px solid black; border-style: solid; border-radius: 4px; }");
#endif

    return  QScriptValue (engine, msg.exec());
}


QScriptValue searchDialogTableView(QScriptContext *context, QScriptEngine *engine)
{
    QAbstractItemView *viewWidget = qobject_cast<QAbstractItemView*>(context->thisObject().toQObject());
    SearchDialog dlg(viewWidget);
    dlg.exec();
    return QScriptValue(engine, 0);
}

#include "sqltablemodel.h"
QScriptValue  sqlTableModelCtor(QScriptContext */*context*/, QScriptEngine *engine)
{
    SqlTableModel* model = new SqlTableModel();
    return engine->newQObject(model, QScriptEngine::ScriptOwnership);
}
